package com.xzzz.irda.guardcat.core.metric;

import com.xzzz.irda.guardcat.core.metric.rocketmq.RocketMQMetricManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 【Core】Rocket 信息
 *
 * @author xzzz
 */
@RestController
@RequestMapping("/guardcat/core/rocketmq")
public class GuardcatRocketMqController {

    @Autowired(required = false)
    private RocketMQMetricManager rocketMQMetricManager;

    /**
     * 所有TOPIC
     *
     * @return topic 集合
     */
    @GetMapping("/topics")
    public Map<String, Set<String>> topics() {
        Map<String, Set<String>> metric = new HashMap<>(2);
        if (rocketMQMetricManager == null) {
            return metric;
        }
        metric.put("producer", rocketMQMetricManager.getProducerTopics());
        metric.put("consumer", rocketMQMetricManager.getConsumerTopics());
        return metric;
    }

}
